
#include<bits/stdc++.h>
#define int long long
using namespace std;

int n;
int T;
const int N=2e5+10;
int va[N];
int maxn=0;
int rl=0,bl=0;
int ans=0;
void dfs(int now,int c)
{
    if(now==n+1)
    {
        maxn=max(maxn,ans);
        return ;
    }
    if(c==0)
    {
        if(rl==0)
        {
            rl=now;
        }
        else
        {
            if(va[rl]==va[now])
            {
                ans+=va[now];
            }
            rl=now;
        }
    }else
    {
        if(bl==0)
        {
            bl=now;
        }
        else
        {
            if(va[bl]==va[now])
            {
                ans+=va[now];
            }
            bl=now;
        }
    }
    cout<<ans<<" ";
    dfs(now+1,0);
    dfs(now+1,1);
}

signed main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);

    cin>>T;
    while(T--)
    {
        maxn=0;
        rl=0;
        bl=0;
        ans=0;
        cin>>n;
        for(int i=1;i<=n;i++) cin>>va[i];
        dfs(1,0);
        dfs(1,1);
        cout<<maxn<<"\n";
    }

    return 0;
}
